Deque<ListNode> q = new LinkedList<>();
while(head!=null){
    q.offer(head);
    head = head.next;
}
for(int i=1;i<=k;i++){
    head = q.pollLast();
}
//System.out.println(head.val);
return head;

public ListNode getKthFromEnd(ListNode head, int k) {
    ListNode pre = head; // pre前指针,head尾指针
    int index = 1;
    while( index <k ){
        head = head.next;
        index ++;
    }
    while(head.next!=null){
        pre = pre.next;
        head = head.next;
    }
    // System.out.println(pre.val);
    return pre;
}